/**
 * 文章详情模块
 */

import request from '@/utils/request'
// import store from '@/store'

export const getArticleById = (articleId) => {
  return request({
    method: 'GET',
    url: `/v1_0/articles/${articleId}`
  })
}

// 关注
export const addFollow = (target) => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target
    }
  })
}

// 取消关注
export const deleteFollow = (target) => {
  return request({
    method: 'DELETE',
    url: `/v1_0/user/followings/${target}`
  })
}

// 收藏
export const addCollect = (target) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/collections',
    data: {
      target
    }
    // headers: {
    //   Authorization: `Bearer ${store.state.user.token}` // 刷新页面没有token了，从外面文章列表进来又有 // 原因请求拦截器写在了用户模块中
    // }
  })
}

// 取消收藏
export const deleteCollect = (target) => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/collections/${target}`
    // headers: {
    //   Authorization: `Bearer ${store.state.user.token}`
    // }
  })
}

// 点赞
export const addLike = (target) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/likings',
    data: {
      target
    }
  })
}

// 取消点赞
export const deleteLike = (target) => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/likings/${target}`
  })
}
